<?php

/**
 * Description of AjaxController
 *
 * @author Samsung
 */
class AjaxController extends Controller {
    
    /*
    public function accessRules(){
        return array(
            array('allow',
                'actions'=>array('defaultimage','deleteimage','defaultvideo','deletevideo'),
                'users'=>array('@'),
            ),
            array('deny'),
        );
    }
    */
    
    public function actions() {
        return array(
            'defaultimage'=>array(
                'class'=>'ext.actions.GalleryAction',
                'module' => Yii::app()->request->getParam('module'),
                'moduleId'=>Yii::app()->request->getParam('id'),
                'imageId'=>Yii::app()->request->getParam('imageId'),
                'action'=>'default',
            ),
            'deleteimage'=>array(
                'class'=>'ext.actions.GalleryAction',
                'module' => Yii::app()->request->getParam('module'),
                'moduleId'=>Yii::app()->request->getParam('id'),
                'imageId'=>Yii::app()->request->getParam('imageId'),
                'action'=>'delete',
            ),
            'defaultvideo'=>array(
                'class'=>'ext.actions.VideoAction',
                'module' => Yii::app()->request->getParam('module'),
                'moduleId'=>Yii::app()->request->getParam('id'),
                'imageId'=>Yii::app()->request->getParam('videoId'),
                'action'=>'default',
            ),
            'deletevideo'=>array(
                'class'=>'ext.actions.VideoAction',
                'module' => Yii::app()->request->getParam('module'),
                'moduleId'=>Yii::app()->request->getParam('id'),
                'imageId'=>Yii::app()->request->getParam('videoId'),
                'action'=>'delete',
            ),
            'shortlist' => array(
                'class' => 'ext.widgets.EShortlist.ShortListAction',
                'module' => Yii::app()->request->getParam('module'),
                'moduleId' => Yii::app()->request->getParam('id'),
            ),
            'like' => array(
                'class' => 'ext.widgets.ELike.LikeAction',
                'module' => Yii::app()->request->getParam('module'),
                'moduleId' => Yii::app()->request->getParam('id'),
            ),
            'abuseItem' => array(
                'class' => 'ext.widgets.EAbuse.AbuseAction',
                'module' => 'Item',
                'moduleId' => Yii::app()->request->getParam('id'),
            ),
            'abusecontestentry' => array(
                'class' => 'ext.widgets.EAbuse.AbuseAction',
                'module' => 'ContestEntry',
                'moduleId' => Yii::app()->request->getParam('id'),
            ),
        );
    }
    
    public function actionCountryname(){
        
        if(!isset($_POST['Address']['country_'])) return;
        $result=Option::country($_POST['Address']['country_']);
        if(Yii::app()->request->isAjaxRequest){
            echo $result;
        }else{
            return $result;
        }
    }
    
    public function actionAccountstate(){
        $model = new Account('userCreate');
        $form = Yii::app()->request->getParam(get_class($model));
        if($form){
            $model->attributes = $form;
        }
        $htmlOptions = array();
        $option = CHtml::listOptions('', $model->stateOption, $htmlOptions);
        if(Yii::app()->request->isAjaxRequest){
            echo $option;
        }else{
            return $option;
        }
    }
    
    public function actionUserstate(){
        $model = new User('userCreate');
        $form = Yii::app()->request->getParam(get_class($model));
        if($form){
            $model->attributes = $form;
        }
        $htmlOptions = array();
        $option = CHtml::listOptions('', $model->stateOption, $htmlOptions);
        if(Yii::app()->request->isAjaxRequest){
            echo $option;
        }else{
            return $option;
        }        
    }
 
    public function actionArticletypeurl(){
        
        $model=Article::model();
        $params = Yii::app()->request->getParam(get_class($model));
        if(isset($params['type_'])){
            $type=$params['type_'];
            $option=array(
                Option::ARTICLE_TYPE_NEWS=>Yii::app()->createAbsoluteUrl('news'),
                Option::ARTICLE_TYPE_EVENT=>Yii::app()->createAbsoluteUrl('event'),
                Option::ARTICLE_TYPE_PROMOTION=>Yii::app()->createAbsoluteUrl('promotion'),
                Option::ARTICLE_TYPE_CAREER=>Yii::app()->createAbsoluteUrl('career'),
                Option::ARTICLE_TYPE_ACCOUNT_DIRECTORY=>Yii::app()->createAbsoluteUrl('account'),
                Option::ARTICLE_TYPE_CONTACT_US=>Yii::app()->createAbsoluteUrl('site/contact'),
                Option::ARTICLE_TYPE_CATALOG=>Yii::app()->createAbsoluteUrl('item'),
            );
            $url=isset($option[$type])? $option[$type]:null;
        }else{
            $url=null;
        }
        if(Environment::isLocal()) $url=str_replace('localhost','127.0.0.1', $url);
        if(Yii::app()->request->isAjaxRequest){
            echo $url;
        }else{
            return $url;
        }
    }
}